{extend name="layout/default" /}
{block name="head"}
<title>数据表列表</title>

{/block}
{block name="content"}
<div class="layui-card">
    <!--模糊搜索区域-->

    <!--数据表格-->
    <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
{/block}
{block name="scripts"}
<!--js逻辑-->
<script>
    layui.use(["element", "jquery", "table", "form", "laydate"], function () {
        let table = layui.table;
        let form = layui.form;
        let laydate = layui.laydate;
        let $ = layui.jquery;

        let userTable = table.render({
            elem: '#tableId',
            url: '{:url("index")}',
            limit: 20,
            page: false,
            toolbar: true,
            toolbar: "#toolbarTpl",
            height: 'full',
            cellMinWidth: 120,
            cols: [[
                { type: "checkbox", fixed: "left" },
                { field: "id", title: "ID", sort: true },
                { field: "name", title: "表名" },
                { field: "comment", title: "描述" },
                { title: "操作", align: "center", fixed: "right", templet: "#operationTpl" }
            ]],
            done: function (res, curr, count) {
                console.info(res, curr, count);
            }
        });

        form.on("submit(search)", function (data) {
            userTable.reload({
                where: data.field,
                page: { curr: 1 }
            });
            return false;
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "batchEnabled":
                    batchEnabled();
                    break;
                case "batchDisabled":
                    batchDisabled();
                    break;
                case "batchDel":
                    batchDel();
                    break;
                case "add":
                    add();
                    break;
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "crud":
                    crud(data.name);
                    break;
                case 'plugin':
                    plugin(data.name);
                    break;
            }
        });


        function crud(res) {
            layer.confirm("确定要crud吗？", function () {
                $.ajax(
                     {

					      url:'{:url('crud')}',
                            data:{name: res},
                            dataType: 'json',
                            type: 'post',

			           	}

                ).done(function (response) {
						//console.log(response);
						if (response.code == 1) {
							console.log(response);
							layer.msg(response.msg, {
                                        icon: 1,
                                        time: 1000
                                    }, function() {
                                    	table.reload('tableId');
                                    });
						} else {
							layer.msg(response.msg, {
                                        icon: 2,
                                        time: 1000
                                    },  function () {

							})
						}
					}).fail(function () {

                });
            })
        }

        function plugin(res) {
            layer.confirm("确定要插件crud吗？", function () {
                $.ajax(
                       {
                    
                            url:'{:url('plugin')}',
                            data:{name: res},
                            dataType: 'json',
                            type: 'post',

			           	}
                
                ).done(function (response) {
						//console.log(response);
						if (response.code == 1) {
							console.log(response);
							layer.msg(response.msg, {
                                        icon: 1,
                                        time: 1000
                                    }, function() {
                                    	table.reload('tableId');
                                    });
						} else {
							layer.msg(response.msg, {
                                        icon: 2,
                                        time: 1000
                                    },  function () {

							})
						}
					}).fail(function () {

                });
            })
        }
    })
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
    <div class="layui-btn-container">

    </div>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    <a href="javascript:" lay-event="crud" class="layui-btn layui-btn-warm layui-btn-xs">一键crud</a>
    <a href="javascript:" lay-event="plugin" class="layui-btn layui-btn-sm layui-btn-xs">一键插件</a>
</script>

<script type="text/html" id="statusTpl">
    {{#  if(d.status == 'normal'){ }}
    <span class="layui-btn layui-btn-normal layui-btn-xs">启用</span>
    {{#  } else if(d.status != 'normal') { }}
    <span class="layui-btn layui-btn-warm layui-btn-xs">停用</span>
    {{#  } }}
</script>

<script type="text/html" id="logoTpl">
    <img src="{{d.avatar}}" style="width: auto;height: 100%;"/>
</script>
<script type="application/javascript">

</script>

{/block}